<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceDeleteToDo extends core {

    public function process() {
        $todo_id = intval($_POST['todo_id']);
        $user_id = intval($_POST['user_id']);
    
        $data = $this->db->get_row("SELECT * FROM todo_lists WHERE `todo_id`='$todo_id' AND `user_id`='$user_id'");
        if ($data) {         
            $query = "DELETE FROM todo_lists WHERE `todo_id`= '$todo_id' AND `user_id`='$user_id'";

            if ($this->db->query($query)===false) {

                $this->_JSONResponse(array('error' => 1, 'msg' => 'Oops, something went wrong. Please try again'));
            } else {             
                $this->_JSONResponse(array('error' => 0, 'msg' => 'Task has been removed'));
            }
        } else {
            $this->_JSONResponse(array('error' => 1, 'msg' => 'Task does not exist'));
        }
    }

}

$processor = new webServiceDeleteToDo();
$processor->process();
?>